<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的店铺</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script th:src="@{/static/main.js}"></script>

    <style>
        .container {
            padding-top: 10px;
        }

        .cover {
            display: inline-block;
            width: 30px;
            height: 30px;
            position: absolute;
            right: 160px;
            top: 9px;
            z-index: 100;
            cursor: pointer;
        }
    </style>
</head>
<body>

<div class="container-fluid" id="app" style="margin-top: 5px;margin-bottom: 100px">

    <div class="container" v-if="stores.length<=0">
        <h3 style="text-align: center">很可惜，空空如也~</h3>
    </div>

    <div class="container" v-if="stores.length>0">

        <div class="row">
            <div class="col-md-12">
                <p style="background-color: #458b74 ; color: white; font-size: 30px; padding-left: 10px; border-radius: 4px">
                    我的餐店</p>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6 col-md-12" v-for="store in stores">
                <div class="thumbnail" style="box-shadow: 5px 5px 3px 0px #CCCCCC">
                    <img v-if="!store.storeImg" src="/static/109951166155909486.jpg" alt="..." class="col-sm-2 col-md-2">
                    <img v-if="store.storeImg" :src="store.storeImg" alt="..." class="col-sm-2 col-md-2">
                    <div class="caption text-left">
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">店铺名:<span
                                v-text="store.storeName">storeName</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">介绍:<span
                                v-text="store.detail">detail</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">
                            经营类型:<span v-text="store.typeName">typeName</span></p>
                        <p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">地址:<span
                                v-text="store.address">address</span></p>
                        <p style="padding-left: 870px;position: relative;bottom: 60px;">

                            <a class="btn btn-success"
                               :href="'/product/sa?storeId='+ store.id + '&storeName=' + store.storeName">餐品管理</a>
                            &nbsp;&nbsp;&nbsp;

                            <span v-if="store.status==1">
                                <a class="btn btn-warning" @click.prevent="updateStore(store.id,store.status)">已暂停营业</a> &nbsp;&nbsp;&nbsp;
                            </span>
                            <a class="btn btn-success" :href="'/item/storeId?storeId='+ store.id">退单管理</a>
                            <span v-if="store.status==0">
                                <a class="btn btn-primary" @click.prevent="updateStore(store.id,store.status)">营业中</a> &nbsp;&nbsp;&nbsp;
                            </span>

                            <a class="btn btn-danger" @click.prevent="deleteStore(store.id)">删除</a> &nbsp;&nbsp;&nbsp;
                        </p>
                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="col-md-offset-5 col-lg-offset-4col-xl-offset-5">
                <ul class="pagination justify-content-center">
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                    <li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a>
                    </li>
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
                </ul>
            </div>
        </div>

    </div>


</div>

<script>

    console.log(".........userapp...........")

    let userapp = new Vue({
        el: "#app"
        ,
        data: {
            stores: [],
            storeTypes: [],

            currentPage: 1,
            pageSize: 2,
            total: 0,
            totalPages: 0,
            currentSeller: '',

        }
        ,
        methods: {
            // initCurrentSeller() {
            // 	$.get("/seller/currentSeller",function (data) {
            // 		alert("data:" + JSON.stringify(data))  //返回的数据要JSON序列化才能正常显示
            // 		userapp.currentSeller=data;
            // 		userapp.sellerId=data.id;
            // 	})
            // },
            initMyStores() {
                let _this = this;
                let params = {
                    currentPage: _this.currentPage,
                    pageSize: _this.pageSize
                }
                console.log(params);
                $.post("/store/currentSellerAndMyStore", params, function (data) {

                    _this.stores = data.records;
                    _this.currentPage = data.current;
                    _this.pageSize = data.size;
                    //数据总量
                    _this.total = data.total;
                    //总页数
                    _this.totalPages = data.pages;
                })
            },
            initStoreTypes() {
                let _this = this;
                $.get("/storeType/all", function (data) {
                    _this.storeTypes = data;
                })
            },
            go(pageNum) {
                //小于1 或者 大于total 或者 仍获取当前页数据 直接返回
                if (pageNum < 1 || pageNum > this.totalPages || pageNum == this.currentPage) {
                    console.log(pageNum + " 无效页码值")
                    return;
                }

                this.currentPage = pageNum;
                this.initMyStores();
            },
            toSearch() {
                //初始化页数
                this.currentPage = 1;
                this.initMyStores();
            },
            updateStore(storeId,status){

                let params = {
                    storeId: storeId,
                    status: status
                }
                console.log(params)
                let _this = this;
                $.post("/store/update", params, function (data) {
                    //状态修改完成后刷新页面数据
                    _this.initMyStores();
                    _this.initStoreTypes();
                })
            },

            deleteStore(storeId) {

                let params = {
                    storeId: storeId
                }
                console.log(params)
                let _this = this;
                $.post("/store/delete", params, function (data) {
                    //状态修改完成后刷新页面数据
                    _this.initMyStores();
                    _this.initStoreTypes();
                })

            }
        }
        ,
        created() {
            this.initMyStores();
            this.initStoreTypes();
        }

    });


</script>

</body>
</html>

